﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Gmantis.Controls.Chart
{
    public abstract class VisualEffect : DependencyObject
    {
        // Events
        internal event EventHandler EffectChanged;

        // Methods
        protected VisualEffect()
        {
        }

        internal virtual UIElement CreateBackgroundEffect(Shape shape)
        {
            return null;
        }

        internal virtual UIElement CreateForegroundEffect(Shape shape)
        {
            return null;
        }

        protected Color? GetColor(Brush brush)
        {
            Color? nullable = null;
            if (brush is SolidColorBrush)
            {
                return new Color?(((SolidColorBrush)brush).Color);
            }
            if (brush is GradientBrush)
            {
                GradientBrush brush2 = (GradientBrush)brush;
                if ((brush2.GradientStops != null) && (brush2.GradientStops.Count > 0))
                {
                    nullable = new Color?(brush2.GradientStops[0].Color);
                }
            }
            return nullable;
        }

        protected Geometry GetGeometry(Shape shape)
        {
            if (shape is Path)
            {
                return ((Path)shape).Data;
            }
            if (shape is Ellipse)
            {
                Ellipse ellipse = (Ellipse)shape;
                double x = 0.5 * ellipse.Width;
                double y = 0.5 * ellipse.Height;
                return new EllipseGeometry { RadiusX = x, RadiusY = y, Center = new Point(x, y) };
            }
            if (shape is Rectangle)
            {
                Rectangle rectangle = (Rectangle)shape;
                return new RectangleGeometry { RadiusX = rectangle.RadiusX, RadiusY = rectangle.RadiusY, Rect = new Rect(0.0, 0.0, rectangle.Width, rectangle.Height) };
            }
            return null;
        }

        protected static void OnChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            VisualEffect sender = obj as VisualEffect;
            if ((sender != null) && (sender.EffectChanged != null))
            {
                sender.EffectChanged(sender, EventArgs.Empty);
            }
        }
    }
}
